package cupk;

import javax.xml.parsers.*;

import cupk.Exit.ExitCommand;
import cupk.Helper.HelpCommand;
import org.w3c.dom.*;

public class ReadFromXML {
    public static Command createCommandFromXml(String xmlFilePath) throws Exception {
//        xmlFilePath = "./src/cupk/abner/Command.xml";
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(xmlFilePath);

        Element root = doc.getDocumentElement();
        String commandType = root.getElementsByTagName("commandType").item(0).getTextContent();

        switch (commandType) {
            case "Exit":
                return new ExitCommand();
            case "Help":
                return new HelpCommand();
            default:
                throw new IllegalArgumentException("Invalid command type: " + commandType);
        }
    }


}